package com.siblings.loan.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.siblings.loan.R
import com.siblings.loan.databinding.DialogBindCardSubmitWarningBinding
import com.siblings.loan.http.HttpHelper
import com.siblings.loan.utils.event.SibEventType

/**
 * Siblings
 * @Author wwdeng
 * @CreateTime: 2024/7/18 13:58
 * @Annotation： 提交警告dialog
 */
class BindCardSubmitWarningDialog: ProDialog {
    private lateinit var binding: DialogBindCardSubmitWarningBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogBindCardSubmitWarningBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.imgClose)
        setOnClickListener(R.id.btnAdd) //继续添加
        setOnClickListener(R.id.btnNoMore) //没有更多
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        when(v!!.id){
            R.id.imgClose,
            R.id.btnNoMore -> {
                HttpHelper.addSibEventAction(SibEventType.CLICK.SIB_CLICK_USER_ACCOUNT_SUBMIT_ONLYONE_TIPS_CANCEL,eventRemark)
            }
            else -> {
                HttpHelper.addSibEventAction(SibEventType.CLICK.SIB_CLICK_USER_ACCOUNT_SUBMIT_ONLYONE_TIPS_CONFIRM,eventRemark)
            }
        }
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addSibEventAction(SibEventType.DIALOG.SIB_DIALOG_USER_ACCOUNT_SUBMIT_ONLY_ONE_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addSibEventAction(SibEventType.DIALOG.SIB_DIALOG_USER_ACCOUNT_SUBMIT_ONLY_ONE_TIPS_DISMISS,eventRemark)
    }
}